/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bombercloud.client;

import bombercloud.commons.BlocoQuebra;
import bombercloud.commons.Request;
import bombercloud.commons.Response;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;

/**
 *
 * @author Delano
 */
public class ThreadFogo extends Thread {

    ObjectInputStream inputStream;
    ObjectOutputStream outputStream;
    Socket socket;
    BlocoQuebra blocoQuebra;
    ArrayList<BlocoQuebra> blocosARemover;
    ArrayList<BlocoQuebra> fogo;
    JPanel panel;

    public ThreadFogo(Socket socket1, ObjectOutputStream objectOutputStream1, BlocoQuebra bl, ArrayList<BlocoQuebra> bar, ArrayList<BlocoQuebra> f, JPanel jp) {
        blocoQuebra = bl;
        blocosARemover = bar;
        fogo = f;
        socket = socket1;
        outputStream = objectOutputStream1;
        panel = jp;
    }

    @Override
    public void run() {
        try {
            sleep(200);
            if (fogo != null && fogo.size() > 0) {
                Request request = new Request();
                request.setType(request.REQUEST_TYPE_DELETE_FOGO);
                request.setParam3(fogo);
                executeRequest(request);
            }
//
//            if (blocosARemover.size() > 0) {
//                Request request2 = new Request();
//                request.setType(request.REQUEST_TYPE_DELETE_BLOCOS);
//                request.setParam3(blocosARemover);
//                executeRequest(request2);
//                panel.repaint();
//            }

        } catch (InterruptedException ex) {
            Logger.getLogger(ThreadBomba.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public synchronized Response executeRequest(Request request) {
        Response response = null;
        try {
            outputStream.writeObject(request);
            outputStream.flush();
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
        return response;
    }
}
